{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}
var
	max,min:integer;
procedure f(n:integer);
var
	a:array[0..9] of integer=(0,0,0,0,0,0,0,0,0,0);
	i,j:integer;
begin
	if(n<=9)then
		a[0]:=3
	else if(n<=99) then
		a[0]:=2
	else if(n<=999) then
		a[0]:=1;
	while(n>0)do
	begin
		a[n mod 10]:=a[n mod 10]+1;
		n:=n div 10;
	end;
	max:=0;
	min:=0;
	j:=1;
	for i:=0 to 9 do
	begin
		while(a[i]>0)do
		begin
			max:=max+j*i;
			min:=min*10+i;
			j:=j*10;
			dec(a[i]);
		end;
	end;
end;
var
	n,step:integer;
begin
	readln(n);
	step:=1;
	f(n);
	while (max-min)<> 6174 do
	begin
		f(max-min);
		inc(step);
	end;
	writeln(step);
end.
